﻿var JourPIDJson;
var JourVesionJson;
var JourPostionJson;
var pageSize = 15;
$(document).ready(function () {

    //按照PID进行 查询
    $.ajax({
        type: "post",
        data: { action: "GetListByPID" },
        dataType: "json",
        url: "../../Ajax/CommunicationAjax.ashx", 
        async: false,
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                JourPIDJson = data.json;
                $("#seleByType").append(InitSelectByPID());
                //InitTaskName(pageclickednumber);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });
    //按照vesion进行 查询
    $.ajax({
        type: "post",
        data: { action: "GetListByVesion" },
        dataType: "json",
        url: "../../Ajax/VersionAjax.ashx",
        async: false,
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                JourVesionJson = data.json;
                $("#seleByVesion").append(InitSelectByVesion());
                //InitTaskName(pageclickednumber);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });
    //按照联网位置
    $.ajax({
        type: "post",
        data: { action: "GetListBySelect" },
        dataType: "json",
        url: "../../Ajax/JournalAjax.ashx",
        async: false,
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                JourPostionJson = data.json;
                $("#seleByPotion").append(InitSelectByPotion());
                //InitTaskName(pageclickednumber);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });
    $("#btnSele").click(function () {
        InitTaskName(1);
    })
    PageClickFunc(1);

    $("#txtIMSI").focus(function () {
        if ($(this).val() == "输入IMSI查询") {
            $(this).val("");
        }
    })

    $("#txtIMSI").blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).attr("default"));
        }

    })

    $("#txtAccount").focus(function () {
        if ($(this).val() == "输入用户系统账号") {
            $(this).val("");
        }
    })

    $("#txtAccount").blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).attr("default"));
        }

    })

    //    $("#seleByType").change(function () {
    //        InitTaskName();
    //    })
})
//查询下拉框选择方法(PID)
function InitSelectByPID() {
    var sel = "";
    sel += "<option>-请选择PID-</option>";
    $.each(JourPIDJson, function (k, v) {
        sel += "<option value='" + v.ID + "'>" + v.Name + "</option>";
    })
    return sel;
}
//查询下拉框选择方法(vesion)
//sel += "<option value='" + v.ID + "' selected='selected'>" + v.Num + "</option>";
function InitSelectByVesion() {
    var sel = "";
    sel += "<option>-选择版本号-</option>";
    $.each(JourVesionJson, function (k, v) {
        sel += "<option value='" + v.Name + "'>" + v.Name + "</option>";
    })
    return sel;
}
//查询下拉框选择方法(potion)
function InitSelectByPotion() {
    var sel = "";
    $.each(JourPostionJson, function (k, v) {
        if (k == 0)
            sel += "<option value='" + v.Name + "' selected='selected'>" + v.Name + "</option>";
        else
            sel += "<option value='" + v.Name + "'>" + v.Name + "</option>";
    })
    return sel;
}
function InitTaskName(pageclickednumber) {
    var Pid = $("#seleByType").val() == null ? "" : $("#seleByType").val();
    //      $("#seleByType>option:selected").text() == '-请选择PID-' ? "" : $("#seleByType").val();

    var vesion = $("#seleByVesion>option:selected").text();
    var potion = $("#seleByPotion").val()
 
    var IMSI = $("#txtIMSI").val() == "输入IMSI查询" ? "" : $("#txtIMSI").val();
    var userAccount = $("#txtAccount").val() == "输入用户系统账号" ? "" : $("#txtAccount").val();
    var StartTime = $("#txtStateTime").val();
    var EndTime = $("#txtEndTime").val();
    $.ajax({
        type: "post",
        data: { action: "GetList", pageIndex: pageclickednumber, pageSize: pageSize, Pid: Pid, vesion: vesion, potion: potion, IMSI: IMSI, StartTime: StartTime, EndTime: EndTime, userAccount: userAccount },
        datatype: "json",
        url: "../../Ajax/JournalAjax.ashx",
        beforSend: function () {
        },
        success: function (data) {
            if (data != null) {
                var json = $.parseJSON(data).json;
                var pageCount = $.parseJSON(data).flag;
                var tbody = "";
                $.each(json, function (k, v) {
                    tbody += "<tr>"
                    tbody += "<td><lable name='lblPid' id='" + v.Id + "'>";
                    tbody += v.Pid;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblMarket'>";
                    tbody += v.Market;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblIMSI'>";
                    tbody += v.IMSI;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblUserAccount'>";
                    tbody += v.UserAccount;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblName'>";
                    tbody += v.Name;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblVesion'>";
                    tbody += v.Vesion;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblPosition'>";
                    tbody += v.Position;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblGameNum'>";
                    tbody += v.GameNum;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblTicketNum'>";
                    tbody += v.TicketNum;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblEggNum'>";
                    tbody += v.EggNum;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblUpStream'>";
                    tbody += decodeURIComponent(v.UpStream).substr(0, 25);
                    tbody += "</lable><lable name='lblUpStream2' style='display:none'>" + decodeURIComponent(v.UpStream) + "</lable</td>";
                    tbody += "<td><lable name='lblDownStream'>";
                    tbody += decodeURIComponent(v.DownStream).substr(0, 25);
                    tbody += "</lable><lable name='lblDownStream2' style='display:none'>" + decodeURIComponent(v.DownStream) + "</lable></td>";
                    tbody += "<td><lable name='lblRequestTime'>";
                    tbody += v.RequestTime;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblTotal_bonus'>";
                    tbody += v.Total_bonus;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblMatch_coin'>";
                    tbody += v.Match_coin;
                    tbody += "</lable></td>";
                    tbody += "<td><lable name='lblGoldNum'>";
                    tbody += v.GoldNum;
                    tbody += "</lable></td>";
                    tbody += "<td>";
                    tbody += "<input type='button' onclick='Update(this)' value='预览'> "
                    if (v.Position == 'GetGameTaskMatch' || v.Position == 'GetGameMain') {
                        tbody += "<input type='button' onclick='BInfo(this)' value='图案信息'>"
                    }
                    tbody += "</td>";
                    tbody += "</tr>"
                })
                $("#tb1").empty().append(tbody)
                $("#pager").pager({ pagenumber: pageclickednumber, pagecount: Math.ceil(pageCount / pageSize), buttonClickCallback: PageClickFunc });
            }
        },
        complete: function () {
        },
        error: function () {
        }
    })
}

PageClickFunc = function (pageclickednumber) {
    InitTaskName(pageclickednumber);
}

function Update(contr) {
    var lbl = $(contr).parent().parent().find("lable[name=lblPid]").first();
    Edit(lbl);
}

function BInfo(contr) {
    var lbl = $(contr).parent().parent().find("lable[name=lblPid]").first();
    Info(lbl);
}
function Edit(lbl) {
    var sortNum = $(lbl);
    var Id = $(lbl).parent().parent().find("lable[name=lblName]").attr("id");
    var data = new Date();
    var content = "";
    if (lbl != null) {
        content = "<table><tr><td>PID：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblPid]").text() + "</lable></td></tr>"
        content += "<tr><td>市场：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblMarket]").text() + "</lable></td></tr>"
        content += "<tr><td>IMSI：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblIMSI]").text() + "</lable></td></tr>"
        content += "<tr><td>用户账号：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=Name]").text() + "</lable></td></tr>"
        content += "<tr><td>版本：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblVesion]").text() + "</lable></td></tr>"
        content += "<tr><td>位置：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblPosition]").text() + "</lable></td></tr>"
        content += "<tr><td>游戏数：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblGameNum]").text() + "</lable></td></tr>"
        content += "<tr><td>彩蛋数：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblEggNum]").text() + "</lable></td></tr>"
        var reg = new RegExp('“', 'g'); //创建正则RegExp对象   
        var lblText = $(lbl).parent().parent().find("lable[name=lblUpStream2]").text();
        lblText = lblText.replace(reg, '"');
        content += "<tr><td>上行：<textarea  cols='50' rows='5' id='txtUpStream' style='font-family:Arial;width:198px;float:right'>" + lblText + "</textarea></td></tr>"
        lblText = $(lbl).parent().parent().find("lable[name=lblDownStream2]").text();
        lblText = lblText.replace(reg, '"');
        content += "<tr><td>下行：<textarea  cols='50' rows='5' id='txtUpStream' style=' font-family:Arial;width:198px;float:right'>" + lblText + "</textarea></td></tr>"
        content += "<tr><td>联网时间：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblRequestTime]").text() + "</lable></td></tr>"
        content += "<tr><td>比赛成绩：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblTotal_bonus]").text() + "</lable></td></tr>"
        content += "<tr><td>比赛币：<lable id='lblPid'>" + $(lbl).parent().parent().find("lable[name=lblMatch_coin]").text() + "</lable></td></tr></table>"
    }
    else {
    }

    $.dialog({
        title: "日志预览",
        content: content,
        button: [
                    {
                        name: "关闭",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
        lock: true,
        drag: false
    });
}
function Info(lbl) {
    var position = $(lbl).parent().parent().find("lable[name=lblPosition]").text()
    var upStreamJson = $.parseJSON($(lbl).parent().parent().find("lable[name=lblUpStream2]").text())
    //比赛模式
    if (position == "GetGameTaskMatch")
        upStreamJson = upStreamJson.match;
    else if (position == "GetGameMain")//经典模式
        upStreamJson = upStreamJson.classic;

    var content = "<table border='1px'><tr><td>图案</td><td>押注总金币</td><td>压中金币</td><td>压中次数</td></tr>";
    if (lbl != null) {
        content += "<tr><td>bar:</td><td>" + upStreamJson.bet_coin[7] + "</td><td>" + upStreamJson.earn_coin[7] + "</td><td>" + upStreamJson.win_times[7] + "</td></tr>";
        content += "<tr><td>77：</td><td>" + upStreamJson.bet_coin[6] + "</td><td>" + upStreamJson.earn_coin[6] + "</td><td>" + upStreamJson.win_times[6] + "</td></tr>";
        content += "<tr><td>星星：</td><td>" + upStreamJson.bet_coin[5] + "</td><td>" + upStreamJson.earn_coin[5] + "</td><td>" + upStreamJson.win_times[5] + "</td></tr>";
        content += "<tr><td>西瓜：</td><td>" + upStreamJson.bet_coin[4] + "</td><td>" + upStreamJson.earn_coin[4] + "</td><td>" + upStreamJson.win_times[4] + "</td></tr>";
        content += "<tr><td>铃铛：</td><td>" + upStreamJson.bet_coin[3] + "</td><td>" + upStreamJson.earn_coin[3] + "</td><td>" + upStreamJson.win_times[3] + "</td></tr>";
        content += "<tr><td>梨子：</td><td>" + upStreamJson.bet_coin[2] + "</td><td>" + upStreamJson.earn_coin[2] + "</td><td>" + upStreamJson.win_times[2] + "</td></tr>";
        content += "<tr><td>橘子：</td><td>" + upStreamJson.bet_coin[1] + "</td><td>" + upStreamJson.earn_coin[1] + "</td><td>" + upStreamJson.win_times[1] + "</td></tr>";
        content += "<tr><td>苹果：</td><td>" + upStreamJson.bet_coin[0] + "</td><td>" + upStreamJson.earn_coin[0] + "</td><td>" + upStreamJson.win_times[0] + "</td></tr>";
    }
    content += "</table>";
    $.dialog({
        title: "图案信息",
        content: content,
        button: [
                    {
                        name: "关闭",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
        lock: true,
        drag: false
    });
}